<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>审核界面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../res/layui/css/layui.css">
    <link rel="stylesheet" href="../../res/css/bootstrap.min.css">
    <script src="../../res/js/jquery-3.1.1.min.js" charset="utf-8"></script>
    <script src="../../res/js/Tools.js"></script>
    <script src="../../res/layui/layui.js"></script>
    <style>
        .layui-form-label{
            width: 100px;
        }
    </style>

    <script type="text/javascript">
        //全局同步
        $.ajaxSetup({
            async: false
        });

    </script>

    <script type="text/javascript">
        $(function () {
            var schemeId = getQueryString("schemeId");
            $("#schemeId").val(schemeId);
            var saId = $("#schemeId").val();
            var sort = getQueryString("sort"); //第二次申请状态
            if(sort == 10){
                var urls = "../../AtsSchemeController/updateAtsSchemeAudit?isva=0&saId="+$("#schemeId").val();
                $.post(urls,null);
            }
            $.ajax({
                url:"../../AtsSchemeController/selectExist",
                type:"post", // 传输类型
                data:{'schemeId' : schemeId},
                success:function(obj){
                    for(var i in obj){
                        if(obj[i].auditState == 10){
                            $("#applyForExp").val(obj[i].applyForExp);
                        }else{
                            // $(".form_class select[name='expertName']").val(obj[i].expertId+','+obj[i].expertName);
                            // set_select_checked(expertName, obj[i].expertId+','+obj[i].expertName);
                            // var expertName = $("#expertName").options;
                            $("#expertNames").val(obj[i].expertId+','+obj[i].expertName);
                            $("#applyForExp").val(obj[i].applyForExp);
                            $("#auExp").attr("readonly","readonly");
                            $("#disagree").attr("hidden","hidden");
                            $("#agree").attr("class","layui-btn layui-btn-disabled");
                            $("#agree").attr("disabled","disabled");

                        }
                    }

                    /*if(obj.auditState > 0){
                        $("#applyForExp").val(obj.applyForExp);
                    }

                    if(obj.auditState > 10){
                        $("#disagree").attr("hidden","hidden");
                        $("#agree").attr("class","layui-btn layui-btn-disabled");
                        $("#agree").attr("disabled","disabled");
                        $("#agree").html("已审核");
                    }*/


                },
                error:function(e){

                }

            });
            $.ajax({
                type:"GET",
                async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                url:"../../AtsSchemeController/selectAtsEmpExpert",//获取option值
                success:function(data){
                    for(var i in data){        //遍历输出LIST添加为option
                        $("#expertName").append("<option value='"+data[i].expertId+','+data[i].expertName+"'>"+data[i].expertName+"</option>");
                    }
                }

            });

            $.ajax({
                type:"GET",
                async:false,     //设为同步请求（异步加载的话后面的遍历方法获取不到option）
                url:"../../AtsSchemeController/atsSchemeAuditSelectBySaId",//获取option值
                data:{ 'saId' : saId },
                success:function(data){
                    for(var i in data){        //遍历输出LIST添加为option
                        if(data[i].auditState == 20 || data[i].auditState == 30 || data[i].auditState == 40){
                            $("#auExp").val(data[i].auExp);
                            $("#agree").html("已同意");
                        }

                        if(data[i].auditState == 21){
                            $("#auExp").val(data[i].auExp);
                            $("#agree").html("已拒绝");
                        }

                    }
                }

            });



        });
        /**

         * 设置select控件选中

         * @param selectId select的id值

         * @param checkValue 选中option的值

         */
        /*function set_select_checked(selectId, checkValue){

            var select = document.getElementById(selectId);

            for (var i = 0; i < select.options.length; i++){

                if (select.options[i].value == checkValue){

                    select.options[i].selected = true;

                    break;  }  }  }*/


    </script>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>审核</legend>
</fieldset>

<div><form class="layui-form" action="" id="inputForm" >

    <div class="layui-form-item">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input type="text" name="saId" readonly="readonly" id ="schemeId" lay-verify="required" autocomplete="off" class="layui-input" hidden>
            <input type="text" name="saName" readonly="readonly" id ="schemeName" lay-verify="required" autocomplete="off" class="layui-input" >
            <input type="text" name="auTime" readonly="readonly" id ="auTime" lay-verify="required" autocomplete="off" class="layui-input" hidden>
            <input type="text" name="auditState" readonly="readonly" id ="auditState" autocomplete="off" class="layui-input" hidden>
            <input type="text" name="expertNames" id="expertNames" hidden>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">申请理由</label>
        <div class="layui-input-block">
            <textarea name="applyForExp" readonly="readonly" id ="applyForExp" placeholder="请输入您的意见和建议" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">申请人</label>
        <div class="layui-input-block">
            <input type="text" name="coachName" readonly="readonly" id ="coachName" lay-verify="required" autocomplete="off" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label" >选择专家</label>
        <div class="layui-input-block">
            <select name="expertName" id="expertName" lay-verify="required" lay-filter="expert">
                <option value="">直接选择或搜索选择</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
            <textarea name="auExp" id ="auExp" lay-verify="required" placeholder="请输入审核意见" class="layui-textarea"></textarea>
        </div>
    </div>



    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" id="agree" lay-filter="agree">同意</button>
            <button type="submit" class="layui-btn layui-btn-danger" id="disagree" lay-submit="" lay-filter="disagree">不同意</button>
        </div>
    </div>
</form></div>



<script type="text/javascript">
    /**
     * 关闭当前弹出层
     */
    function closeWindow(){
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    }

</script>
<script>
    layui.use(['form', 'layedit', 'layer', 'laydate','tree','util','upload'], function(){
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , tree = layui.tree
            ,util = layui.util
            ,upload = layui.upload;

        $("#expertName").val($("#expertNames").val());
        if($("#expertName").val() != ""){
            $("#expertName").attr("disabled","disabled");
        }

        form.render();

        //自定义验证规则
        form.verify({
            files: function(value){
                if(value.length == 0){
                    return '必须上传附件1';
                }
            }

            ,content: function(value){
                layedit.sync(editIndex);
            }
        });

        laydate.render({
            elem: '#auTime',
            value: new Date(),
            type: 'datetime'
        });


        //同意的监听提交
        form.on('submit(agree)', function(data){
            var urls = "../../AtsSchemeController/updateAuditState?sort=20&schemeId="+$("#schemeId").val()+"&remark="+$("select[name='expertName']").val();
            $.post(urls,null);
            $("#auditState").val("20");
            var url = "../../AtsSchemeController/atsSchemeAuditMapperInsert?isva=1";
            var formData = new FormData(document.getElementById("inputForm"));
            //传输路径
            $.ajax({
                url:url,
                type:"post", // 传输类型
                data:formData, // 数据
                async:false, // 全局同步
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    // alert("操作成功");
                    //     layer.alert("操作成功");
                    layer.msg(obj.msg,{
                        icon:1,
                        time:1000,
                    },function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.layui.table.reload('schemeId');
                    });
                    return false ;


                },
                error:function(e){
                    alert("操作失败");
                    return false ;
                }
            });

            return false ;
            // closeWindow();//关闭窗口

        });

        //不同意的监听提交
        form.on('submit(disagree)', function(data){
            var urls = "../../AtsSchemeController/updateAuditState?sort=21&schemeId="+$("#schemeId").val();
            $.post(urls,null);
            /*var urles = "../../AtsSchemeController/atsSchemeExpertUpdateByPrimaryKeySelective?isva=0&schemeId="+$("#schemeId").val();
            $.post(urles,null);*/

            $("#auditState").val("21");
            var url = "../../AtsSchemeController/atsSchemeAuditMapperInsert?isva=1";
            var formData = new FormData(document.getElementById("inputForm"));
            //传输路径
            $.ajax({
                url:url,
                type:"post", // 传输类型
                data:formData, // 数据
                async:false, // 全局同步
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    // alert("操作成功");
                    //     layer.alert("操作成功");
                    layer.msg(obj.msg,{
                        icon:1,
                        time:1000,
                    },function(){
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        parent.layui.table.reload('schemeId');
                    });
                    return false ;


                },
                error:function(e){
                    alert("操作失败");
                    return false ;
                }
            });

            return false ;
            // closeWindow();//关闭窗口

        });



    });

</script>

</body>
</html>